package com.slh.touchandroid.adapter;

import java.util.ArrayList;

import com.slh.touchandroid.R;
import com.slh.touchandroid.model.FloatInfo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class FunctionApdater extends BaseAdapter {
	private Context context;
	private int resId;
	private ArrayList<FloatInfo> floatInfos;

	public FunctionApdater(Context context, int resId,
			ArrayList<FloatInfo> floatInfos) {
		super();
		this.context = context;
		this.resId = resId;
		this.floatInfos = floatInfos;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return floatInfos.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return floatInfos.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(resId, null);
			holder = new Holder();
			holder.tvName = (TextView) convertView.findViewWithTag(context
					.getString(R.string.tag_name));
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}
		FloatInfo info = floatInfos.get(position);
		holder.tvName.setText(info.name);
		holder.tvName.setCompoundDrawablesWithIntrinsicBounds(info.resource, 0,
				0, 0);
		return convertView;
	}

	static class Holder {
		TextView tvName;
	}
}
